package _1Cookie;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/setcookie")
public class SetCookiesServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

       //1.创建cookie对象
        Cookie c1=new Cookie("name","lisi");

        //2.设置保存时间
        c1.setMaxAge(3*60);

        //3.添加到响应对象中
        resp.addCookie(c1);

        resp.setContentType("text/html;charset=utf-8");
        PrintWriter pw=resp.getWriter();

        pw.print("cookie");
    }
}
